﻿#region
/*******************************************************************************
** File Name:		    IDCreaterService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class IDCreaterService : IIDCreaterService
    {
		 IIDCreater iDCreater = new IDCreaterRepository();
		 
		 #region  Auto Generation
		 
        public void AddIDCreater(IDCreaterModel model)
        {
			EIDCreater entity = ConvertModelToEntity(model);
			
            iDCreater.AddIDCreater(entity);
        }

		public void UpdateByIDName (IDCreaterModel model)
		{
			EIDCreater entity = ConvertModelToEntity(model);

            iDCreater.UpdateByIDName(entity);

		}

		public void DeleteByIDName (System.String iDName)
		{
		
            iDCreater.DeleteByIDName(iDName);

		}
		 
        public IDCreaterModel GetByIDName (System.String iDName)
        {
        
			EIDCreater entity = iDCreater.GetByIDName(iDName);
			
            IDCreaterModel model = ConvertEntityToModel(entity);


            return model;
        }
        
		public IDCreaterModel ConvertEntityToModel(EIDCreater entity)
		{
			if (entity == null)
            {
                return null;
            }
			IDCreaterModel model = new IDCreaterModel();
                        model.IDName = entity.IDName;
                        model.CurrentCount = entity.CurrentCount;
                        model.Description = entity.Description;
                        model.CreateTime = entity.CreateTime;
                        return model;
		}
		
		public EIDCreater ConvertModelToEntity(IDCreaterModel model)
		{
			if (model == null)
            {
                return null;
            }
			EIDCreater entity = new EIDCreater();
                        entity.IDName = model.IDName;
                        entity.CurrentCount = model.CurrentCount;
                        entity.Description = model.Description;
                        entity.CreateTime = model.CreateTime;
                        return entity;
		}
		
		#endregion

        public int GetNewID(string idName, string description, int seed)
        {
            return iDCreater.GetNewID(idName, description, seed);
        }
    }
}